<include file="common/header_lixin" title="{$title}" />
<div class="page">
    <div class="page-hd">
        <div class="header bor-1px-b">
    <div class="header-left">
        <a href="javascript:history.go(-1)" class="left-arrow"></a>
    </div>
    <div class="header-title">{$title}</div>
    <div class="header-right">
        <a href="#"></a>
    </div>
</div>
    </div>

    <div class="page-bd">
        <!-- 页面内容-->
        <div class="order_box">
            <div class="order_title">
                <if condition="$data.seller_user_id eq $user_id">
                    <if condition="$data['status'] eq 2">
                        <img src="__PUBLIC__/assets/images/icon_time1.png" alt="">
                        <span class="text-main">买家正在付款</span>
                        <elseif condition="$data['status'] eq 3"/>
                        <img src="__PUBLIC__/assets/images/icon_time1.png" alt="">
                        <span class="text-main">买家已确认向您账号转账</span>
                        <elseif condition="$data['status'] eq 4"/>
                        <img src="__PUBLIC__/assets/images/icon_time2.png" alt="">
                        <span class="text-main">交易成功</span>
                        <elseif condition="$data['status'] eq -1"/>
                        <img src="__PUBLIC__/assets/images/icon_time3.png" alt="">
                        <span class="text-main">订单已取消</span>
                    </if>
                    <else/>
                    <if condition="$data['status'] eq 2">
                        <img src="__PUBLIC__/assets/images/icon_time1.png" alt="">
                        <span class="text-main">等待您支付</span>
                        <elseif condition="$data['status'] eq 3"/>
                        <img src="__PUBLIC__/assets/images/icon_time1.png" alt="">
                        <span class="text-main">等待卖家放款</span>
                        <elseif condition="$data['status'] eq 4"/>
                        <img src="__PUBLIC__/assets/images/icon_time2.png" alt="">
                        <span class="text-main">交易成功</span>
                        <elseif condition="$data['status'] eq -1"/>
                        <img src="__PUBLIC__/assets/images/icon_time3.png" alt="">
                        <span class="text-main">订单已取消</span>
                    </if>
                </if>

            </div>
            <div class="weui-cells mt0 border-none">
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>订单时间：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.create_time|date="Y-m-d H:i:s",###}</div>
                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>订单号：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.order_sn}</div>
                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <if condition="$data.seller_user_id eq $user_id">
                            <p>买家：</p>
                            <else/>
                            <p>卖家：</p>
                        </if>
                    </div>
                    <if condition="$data.seller_user_id eq $user_id">
                        <if condition="$data.buyer_user_id">
                            <div class="weui-cell__bd text-gray2">{$data.bnickname}</div>
                            <else/>
                            <div class="weui-cell__bd text-gray2">未接单</div>
                        </if>
                        <else/>
                        <if condition="$data.seller_user_id">
                            <div class="weui-cell__bd text-gray2">{$data.snickname}</div>
                            <else/>
                            <div class="weui-cell__bd text-gray2">未接单</div>
                        </if>

                    </if>

                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <div class="weui-cell__hd">
                            <if condition="$data.seller_user_id eq $user_id">
                                <p>买家联系方式：</p>
                                <else/>
                                <p>卖家联系方式：</p>
                            </if>
                        </div>
                    </div>
                    <if condition="$data.seller_user_id eq $user_id">
                        <if condition="$data.buyer_user_id">
                            <div class="weui-cell__bd text-gray2">{$data.bmobile}</div>
                            <else/>
                            <div class="weui-cell__bd text-gray2">未接单</div>
                        </if>
                        <else/>
                        <if condition="$data.seller_user_id">
                            <div class="weui-cell__bd text-gray2">{$data.smobile}</div>
                            <else/>
                            <div class="weui-cell__bd text-gray2">未接单</div>
                        </if>

                    </if>

                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>单价：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.curr_price}$/ACC</div>
                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>数量：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.number} ACC</div>
                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>交易金额：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.total_price} $ ({$data.total_price * $prc_rate}元)</div>
                </div>
                <if condition="$data.bill_credit">
                    <div class="weui-cell border-none flex-start">
                        <div class="weui-cell__hd">
                            <p>打款凭证：</p>
                        </div>
                        <div class="weui-cell__bd pz_img">
                            <img src="{$data.bill_credit}" alt="">
                        </div>
                    </div>
                </if>

            </div>
        </div>
        <div class="order_box mt30">
            <div class="order_title">
                <span>支付宝</span>
            </div>
            <div class="weui-cells mt0 border-none">
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>收款人：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.account_name}</div>
                </div>
                <div class="weui-cell border-none">
                    <div class="weui-cell__hd">
                        <p>收款账号：</p>
                    </div>
                    <div class="weui-cell__bd text-gray2">{$data.account}</div>
                </div>
                <div class="weui-cell border-none flex-start">
                    <div class="weui-cell__hd">
                        <p>账号二维码：</p>
                    </div>
                    <div class="weui-cell__bd bd_code">
                        <img src="{$data.account_code}" alt="" id="wx_img">
                    </div>
                </div>
            </div>
        </div>

        <if condition="$data.buyer_user_id eq $user_id" >
            <if condition="$data['status'] eq 2"/>
                <div class="ss_notice">
                    <img src="__PUBLIC__/assets/images/icon_4.png" alt="">
                    <span>请在30分钟内，向以上收款方式支付，确认付款成功后，点击下面按钮【我已付款】。卖家将在30分钟内放款，逾时请申诉联系平台。</span>
                </div>
                <div class="weui-cells__title mt0">上传凭证</div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell">
                        <div class="weui-cell__bd">
                            <div class="weui-uploader">
                                <div class="weui-uploader__bd">
                                    <!--<ul class="weui-uploader__files" id="uploaderFiles">-->
                                    <!--<li class="weui-uploader__file" style="background-image:url(__PUBLIC__/assets/images/index_banner.jpg)"></li>-->
                                    <!--</ul>-->
                                    <div class="weui-uploader__input-box" id="fileList">
                                        <input id="uploaderInput" onchange="handleFiles(this)" class="weui-uploader__input" type="file" accept="image/*" multiple="">
                                        <input type="hidden" name="bill_credit" value="{$alipay['account_code']}"/>
                                        <div id="account_prc"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </if>
        </if>


        <div class="weui-btn-area mt0">
            <if condition="$data.seller_user_id eq $user_id">
                <if condition="$data['status'] eq 2">
                    <!--等待买家付款-->
                    <elseif condition="$data['status'] eq 3"/>
                    <!--买家已付款，等待放款-->
                    <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="confirm_complete({$data.id})">确认到账，放款</a>
                    <a href="javascript:;" onclick="complaint_judge({$data.id})" class="weui-btn weui-btn_primary white_btn">提交申诉</a>
                    <elseif condition="$data['status'] eq 4"/>
                    <!--交易完成-->
                    <elseif condition="$data['status'] eq -1"/>
                    <!--订单关闭-->
                </if>
                <else/>
                <if condition="$data['status'] eq 2">
                    <div class="ss_notice">
                        <img src="__PUBLIC__/assets/images/icon_4.png" alt="">
                        <span>我已知晓，需在付款后点击下面按钮（恶意操作将被拉黑账号）</span>
                    </div>
                    <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="confirm_pay({$data.id})">我已打款</a>
                    <elseif condition="$data['status'] eq 3"/>
                    <a href="javascript:;"  onclick="complaint_judge({$data.id})" class="weui-btn weui-btn_primary">申诉</a>
                    <!--等待放款-->
                    <elseif condition="$data['status'] eq 4"/>
                    <!--交易完成-->
                    <elseif condition="$data['status'] eq -1"/>
                    <!--订单关闭-->
                </if>
            </if>

        </div>
    </div>
    <include file="common/footer_lixin"/>
</div>


<script>
    $(function() {
        FastClick.attach(document.body);
    });
</script>
<script type="text/javascript">
    (function(win){
        var callMobile = function (handlerInterface, handlerMethod, parameters){
            var dic = {'handlerInterface':handlerInterface,'function':handlerMethod,'parameters': parameters};
            win.webkit.messageHandlers[handlerInterface].postMessage(dic);
        }
        var init = function(){
            if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){
                var instruct = {};
                if ( !win.app || typeof win.app.Scavenging !== 'function') {
                    instruct.Scavenging = function () {  //获取微信开放平台code
                        callMobile('Photo','AppReturnBase64Image',{});
                    }
                }
                win.app = instruct;
            }
        }
        win.init_ISO = init;
    })(window);

    function AppReturnBase64Image(base64imag){
        var html = '';
        html += '< img style="width: 100%;height: 90%;" src="' + base64imag + '" alt="" class="" />';

        $('#fileList').removeClass('weui-uploader__input-box');
        img = new Image();
        img.src = base64imag;
        img.width = 77;
        img.height = 77;
        $('#account_prc').html(img); //上传了收款码显示在页面
        $.showLoading('图片上传中'); // Loading
        $.ajax({
            type: "POST",
            url: "{:U('Dcworld/Member/baseUploadImg')}",
            data: {file_img:base64imag,file_name:'uploaderInput'},
            dataType: 'json',
            success: function (data) {
                $.hideLoading();
                $('input[name=account_code]').val(data.data.data);
            }
        });
    }

    window.URL = window.URL || window.webkitURL;
    function handleFiles(obj) {
        fileList = document.getElementById("fileList");
        var files = obj.files;
        console.log(files);
        img = new Image();

        if(window.URL){
            img.src = window.URL.createObjectURL(files[0]); //创建一个object URL，并不是你的本地路径
            img.onload = function(e) {
                window.URL.revokeObjectURL(this.src); //图片加载后，释放object URL
            }
            if(fileList.firstElementChild){
                // fileList.removeChild(fileList.firstElementChild);
            }
        }else if(window.FileReader){
            //opera不支持createObjectURL/revokeObjectURL方法。我们用FileReader对象来处理
            var reader = new FileReader();
            reader.readAsDataURL(files[0]);
            reader.onload = function(e){
                img.src = this.result;
            }
        }else{
            //ie
            obj.select();
            obj.blur();
            var nfile = document.selection.createRange().text;
            document.selection.empty();
            img.src = nfile;
        }
        img.width = 77;
        img.height = 77;
        $('#fileList').removeClass('weui-uploader__input-box');
        $('#account_prc').html(img); // 显示选中的图片

        // ajax上传图片
        var upload_img = new FormData();
        upload_img.append('uploaderInput',files[0]);
        upload_img.append('file_name','uploaderInput');

        $.showLoading('图片上传中'); // Loading
        $.ajax({
            type: "POST",
            url: "{:U('Acc/Transaction/uploadImg')}",
            data: upload_img,
            dataType: 'json',
            contentType: false,
            cache: false,
            processData:false,
            success: function (data) {
                $.hideLoading();
                if(data.data.status == 1){
                    //将地址存入input框
                    $('input[name=bill_credit]').val(data.data.data);
                }else if(data.data.status == -1) {
                    $.toast(data.data.data, 'cancel');
                    return false;
                }else{
                    $.toast('网络开小差啦，请重新提交', 'cancel');
                    return false;
                }
            }
        });
    }
</script>
<script>
    var prevent_duplicate_clicks = 0;//防止重复点击
    /**
     * 我已打款
     */
    function confirm_pay(id){
        if(prevent_duplicate_clicks == 1){
            return ;
        }
        prevent_duplicate_clicks = 1;
        var images =  $('input[name=bill_credit]').val();
        var data={
            id:id,
            status:3,
            bill_credit:images
        }

        $.ajax({
            type : "POST",
            dataType:"JSON",
            url:"/index.php/Acc/Transaction/trade_handle",
            data : data,// 你的formid
            success: function(res){
                console.log(res);
                if(res.code==0){
                    $.toast("确认打款成功！",1500,function(){
                        window.location.reload();
                    });
                }else{
                    prevent_duplicate_clicks = 0;
                    $.toast(res.msg,2000,function(){
                        window.location.reload();
                    });
                }
            }
        });
    }

    /**
     * 卖家确认放款
     */
    function confirm_complete(id){
        if(prevent_duplicate_clicks == 1){
            return ;
        }
        prevent_duplicate_clicks = 1;
        var data={
            id:id,
            status:4,
        }
        $.ajax({
            type : "POST",
            dataType:"JSON",
            url:"/index.php/Acc/Transaction/trade_handle",
            data : data,// 你的formid
            success: function(res){

                if(res.code==0){
                    $.toast("确认放款成功！",1500,function(){
                        window.location.reload();
                    });
                }else{
                    prevent_duplicate_clicks = 0;
                    $.toast(res.msg,2000,function(){
                        window.location.reload();
                    });
                }
            }
        });
    }

    function complaint_judge(id){

        $.ajax({
            type : "POST",
            dataType:"JSON",
            url:"/index.php/Acc/Transaction/complaint_judge",
            data : {id:id},// 你的formid
            success: function(res){
                console.log(res);
                if(res.code==0){
                    window.location.href = '/index.php/Acc/Transaction/complaint/id/'+id;

                }else{
                    $.toast(res.msg,2000);
                }
            }
        });
    }
</script>
</body>
</html>